(:
  A procedure to select the contents of the "chat" interventions
:)
declare boundary-space strip;
import module namespace
    jj = "http://kumquat.emse.fr/utilitaires"
    at "jjutils.xq" ;


<display>{

let $t := $arguments[1]

let $d :=doc($t)//trace/record[message/messageHeader/@messageType="GenericType" and message/messageHeader/@UserName!="SERVER"]

for $e at $p in $d
  return

  if ($e/message/ToolMessage/ChatMessage) 
    then
    (: 
      chatTool
     :)
    <item>{ 
      <info name="type">coffee-chatTool</info>,
      <info name="time"><time><date>{fn:string($e/message/messageTimestamp/@millis)}</date></time></info>,
    <info name="src-anchor"><anchor>{
      <doc>{ $t }</doc>,
      <path>{jj:build-Path($e)}</path>
    }</anchor></info>,
      <info name="user">{string($e/message/messageHeader/@UserName)}</info>,
      <info name="content"><text>{string($e/message/ToolMessage/ChatMessage/@text)}</text></info>
    }</item>
    else  

  if ($e/message/ToolMessage/graphicalToolMessage) 
    then
    (: 
      graphicalTool
     :)
    <item>{ 
      <info name="type">coffee-graphicalTool</info>,
      <info name="time"><time><date>{fn:string($e/message/messageTimestamp/@millis)}</date></time></info>,
    <info name="src-anchor"><anchor>{
      <doc>{ $t }</doc>,
      <path>{jj:build-Path($e)}</path>
    }</anchor></info>,
      <info name="user">{string($e/message/messageHeader/@UserName)}</info>,
      <info name="content">
	<type>{string($e/message/ToolMessage/graphicalToolMessage/@type)}</type>
        <description>{string($e/message/ToolMessage/graphicalToolMessage/@description)}</description>
        <text>{string($e/message/ToolMessage/graphicalToolMessage/@text)}</text>
      </info>
    }</item>
    else

  if ($e/message/ToolMessage/ProjectorTextMessage) 
    then
    (: 
      projectorTool
     :)
    <item>{ 
      <info name="type">coffee-projectorTool</info>,
      <info name="time"><time><date>{fn:string($e/message/messageTimestamp/@millis)}</date></time></info>,
    <info name="src-anchor"><anchor>{
      <doc>{ $t }</doc>,
      <path>{jj:build-Path($e)}</path>
    }</anchor></info>,
      <info name="user">{string($e/message/messageHeader/@UserName)}</info>,
      <info name="content">
        <text>{string($e/message/ToolMessage/ProjectorTextMessage/@text)}</text>
        <position>{string($e/message/ToolMessage/ProjectorTextMessage/@position)}</position>
      </info>
    }</item>
    else

  if ($e/message/ToolMessage/NoteMessage) 
    then
    (: 
      noteTool
     :)
    <item>{ 
      <info name="type">coffee-noteTool</info>,
      <info name="time"><time><date>{fn:string($e/message/messageTimestamp/@millis)}</date></time></info>,
    <info name="src-anchor"><anchor>{
      <doc>{ $t }</doc>,
      <path>{jj:build-Path($e)}</path>
    }</anchor></info>,
      <info name="user">{string($e/message/messageHeader/@UserName)}</info>,
      <info name="content">
        <text>{string($e/message/ToolMessage/NoteMessage/@text)}</text>
        <position>{string($e/message/ToolMessage/NoteMessage/@position)}</position>
      </info>
    }</item>

    else
    ()
(:
    <item>{$e/message/ToolMessage}</item>
:)

}</display>
